﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Text;
using System.Windows;
using System.Windows.Data;
using Microsoft.Practices.Prism.Commands;
using ParaEditor.Common;
using ParaEditor.DAO.ParaDAO;
using ParaEditor.Desktop.Interfaces;
using ParaEditor.Domain.Entities;
using ParaEditor.Infrastructure;

namespace ParaEditor.Desktop.ViewModel
{
    [Export(typeof(IPara4006ViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class Para4006ViewModel : ViewModelBase, IPara4006ViewModel
    {
        private Para4006DAO paramDao;
        private string tmpByte = "";
        
        private ICollectionView infoVerList;
        public ICollectionView InfoVerList
        {
            get
            {
                return infoVerList;
            }
            set
            {
                this.infoVerList = value;
                this.RaisePropertyChangedEvent("InfoVerList");
            }
        }

        private ICollectionView paraCollectionDetail;
        public ICollectionView ParaCollectionDetail
        {
            get
            {
                return this.paraCollectionDetail;
            }
            set
            {
                this.paraCollectionDetail = value;
                this.RaisePropertyChangedEvent("ParaCollectionDetail");
            }
        }

        private ICollectionView xingQiCollection;
        public ICollectionView XingQiCollection
        {
            get
            {
                return this.xingQiCollection;
            }
            set
            {
                this.xingQiCollection = value;
                this.RaisePropertyChangedEvent("XingQiCollection");
            }
        }

        private ICollectionView xiaoShiCollection;
        public ICollectionView XiaoShiCollection
        {
            get
            {
                return this.xiaoShiCollection;
            }
            set
            {
                this.xiaoShiCollection = value;
                this.RaisePropertyChangedEvent("XiaoShiCollection");
            }
        }

        private ICollectionView minCollection;
        public ICollectionView MinCollection
        {
            get
            {
                return this.minCollection;
            }
            set
            {
                this.minCollection = value;
                this.RaisePropertyChangedEvent("MinCollection");
            }
        }

        private Visibility editGroupBoxVisible;
        public Visibility EditGroupBoxVisible
        {
            get
            {
                return this.editGroupBoxVisible;
            }
            set
            {
                this.editGroupBoxVisible = value;
                this.RaisePropertyChangedEvent("EditGroupBoxVisible");
            }
        }

        private int recordID;
        public int RecordID
        {
            get
            {
                return this.recordID;
            }
            set
            {
                this.recordID = value;
                this.RaisePropertyChangedEvent("RecordID");
            }
        }

        //Button
        public DelegateCommand AddParamCommand { get; private set; }
        public DelegateCommand DelParamCommand { get; private set; }
        public DelegateCommand SaveParamCommand { get; private set; }
        public DelegateCommand CanclEditParamCommand { get; private set; }
        public DelegateCommand NewVersionCommand { get; private set; }
        public DelegateCommand CopyCurrentVersionCommand { get; private set; }

        [ImportingConstructor]
        public Para4006ViewModel()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 672; i ++)
            {
                sb.Append("1");
            }
            tmpByte = sb.ToString();
            sb.Clear();

            //初始化星期
            XingQi xq1 = new XingQi("星期天");
            XingQi xq2 = new XingQi("星期一");
            XingQi xq3 = new XingQi("星期二");
            XingQi xq4 = new XingQi("星期三");
            XingQi xq5 = new XingQi("星期四");
            XingQi xq6 = new XingQi("星期五");
            XingQi xq7 = new XingQi("星期六");
            XingQi xq8 = new XingQi("不设置高峰时段");
            ObservableCollection<XingQi> XingQiList = new ObservableCollection<XingQi>();
            XingQiList.Add(xq1);
            XingQiList.Add(xq2);
            XingQiList.Add(xq3);
            XingQiList.Add(xq4);
            XingQiList.Add(xq5);
            XingQiList.Add(xq6);
            XingQiList.Add(xq7);
            XingQiList.Add(xq8);
            //初始化小时
            XiaoShi xs0 = new XiaoShi("00:00-01:00");
            XiaoShi xs1 = new XiaoShi("01:00-02:00");
            XiaoShi xs2 = new XiaoShi("02:00-03:00");
            XiaoShi xs3 = new XiaoShi("03:00-04:00");
            XiaoShi xs4 = new XiaoShi("04:00-05:00");
            XiaoShi xs5 = new XiaoShi("05:00-06:00");
            XiaoShi xs6 = new XiaoShi("06:00-07:00");
            XiaoShi xs7 = new XiaoShi("07:00-08:00");
            XiaoShi xs8 = new XiaoShi("08:00-09:00");
            XiaoShi xs23 = new XiaoShi("09:00-10:00");
            XiaoShi xs9 = new XiaoShi("10:00-11:00");
            XiaoShi xs10 = new XiaoShi("11:00-12:00");
            XiaoShi xs11 = new XiaoShi("12:00-13:00");
            XiaoShi xs12 = new XiaoShi("13:00-14:00");
            XiaoShi xs13 = new XiaoShi("14:00-15:00");
            XiaoShi xs14 = new XiaoShi("15:00-16:00");
            XiaoShi xs15 = new XiaoShi("16:00-17:00");
            XiaoShi xs16 = new XiaoShi("17:00-18:00");
            XiaoShi xs17 = new XiaoShi("18:00-19:00");
            XiaoShi xs18 = new XiaoShi("19:00-20:00");
            XiaoShi xs19 = new XiaoShi("20:00-21:00");
            XiaoShi xs20 = new XiaoShi("21:00-22:00");
            XiaoShi xs21 = new XiaoShi("22:00-23:00");
            XiaoShi xs22 = new XiaoShi("23:00-00:00");
            ObservableCollection<XiaoShi> XiaoShiList = new ObservableCollection<XiaoShi>();
            XiaoShiList.Add(xs0);
            XiaoShiList.Add(xs1);
            XiaoShiList.Add(xs2);
            XiaoShiList.Add(xs3);
            XiaoShiList.Add(xs4);
            XiaoShiList.Add(xs5);
            XiaoShiList.Add(xs6);
            XiaoShiList.Add(xs7);
            XiaoShiList.Add(xs8);
            XiaoShiList.Add(xs23);
            XiaoShiList.Add(xs9);
            XiaoShiList.Add(xs10);
            XiaoShiList.Add(xs11);
            XiaoShiList.Add(xs12);
            XiaoShiList.Add(xs13);
            XiaoShiList.Add(xs14);
            XiaoShiList.Add(xs15);
            XiaoShiList.Add(xs16);
            XiaoShiList.Add(xs17);
            XiaoShiList.Add(xs18);
            XiaoShiList.Add(xs19);
            XiaoShiList.Add(xs20);
            XiaoShiList.Add(xs21);
            XiaoShiList.Add(xs22);
            //分钟
            Min m1 = new Min("0到15分钟");
            Min m2 = new Min("15到30分钟");
            Min m3 = new Min("30到45分钟");
            Min m4 = new Min("45到60分钟");
            ObservableCollection<Min> MinList = new ObservableCollection<Min>();
            MinList.Add(m1);
            MinList.Add(m2);
            MinList.Add(m3);
            MinList.Add(m4);

            XingQiCollection = CollectionViewSource.GetDefaultView(XingQiList);
            XiaoShiCollection = CollectionViewSource.GetDefaultView(XiaoShiList);
            MinCollection = CollectionViewSource.GetDefaultView(MinList);

            paramDao = new Para4006DAO();
            InfoVerList = CollectionViewSource.GetDefaultView(paramDao.GetAllVersion());
            if (paramDao.GetAllVersion().Count == 0)
            {
                Microsoft.Windows.Controls.MessageBox.Show("当前参数无任何参数版本");
            }
            InfoVerList.CurrentChanged += InfoVerList_CurrentChanged;

            EditGroupBoxVisible = Visibility.Hidden;
            //Button
            this.AddParamCommand = new DelegateCommand(this.AddParam);
            this.DelParamCommand = new DelegateCommand(this.DelParam);
            this.SaveParamCommand = new DelegateCommand(this.SaveParam);
            this.CanclEditParamCommand = new DelegateCommand(this.CanclEditParam);
            this.NewVersionCommand = new DelegateCommand(this.NewVersion);
            this.CopyCurrentVersionCommand = new DelegateCommand(this.CopyCurrentVersion);
        }

        private void AddParam()
        {
            if (InfoVerList.CurrentItem == null)
            {
                Microsoft.Windows.Controls.MessageBox.Show("请添加参数版本！才可进行添加");
            }
            else
            {
                EditGroupBoxVisible = Visibility.Visible;
            }
        }

        private void CopyCurrentVersion()
        {
            //查询当前版本
            ObservableCollection<Para4006> currentVersionParam = new ObservableCollection<Para4006>();
            int infoVer = (int)InfoVerList.CurrentItem;
            currentVersionParam = paramDao.GetObjectByInfoVer(infoVer);

            if (currentVersionParam.Count != 0)
            {
                Para4006 param = null;
                Para4006Pk paramPk = null;
                int newVersion = paramDao.GetMaxID() + 1;
                foreach (Para4006 item in currentVersionParam)
                {
                    param = new Para4006();
                    paramPk = new Para4006Pk();
                    //编辑参数
                    paramPk.infoVer = newVersion;
                    paramPk.recordId = item.para4006Pk.recordId;

                    param.timeDef = item.timeDef;
                    param.para4006Pk = paramPk;

                    ResultValue result = paramDao.CreateObject(param);
                    if (result.Code != 0)
                    {
                        Microsoft.Windows.Controls.MessageBox.Show("复制过程中出现错误!错误信息：" + result.Msg);
                    }
                }
                //刷新
                ObservableCollection<Para4006> paraCollection = paramDao.GetObjectByInfoVer(newVersion);
                if (paraCollection.Count > 0)
                {
                    string timeDef = paraCollection[0].timeDef;
                    ParaCollectionDetail = CollectionViewSource.GetDefaultView(convert2ParamDetail(timeDef));
                }
                else
                {
                    ParaCollectionDetail = null;
                }
                InfoVerList = CollectionViewSource.GetDefaultView(paramDao.GetAllVersion());
                InfoVerList.CurrentChanged += InfoVerList_CurrentChanged;
            }
            else
            {
                Microsoft.Windows.Controls.MessageBox.Show("所查询的当前版本没有数据,不可进行复制");
            }
        }

        private void NewVersion()
        {
            ObservableCollection<int> infoVerCollection = new ObservableCollection<int>();
            infoVerCollection = paramDao.GetAllVersion();
            int newVersion = paramDao.GetMaxID() + 1;
            infoVerCollection.Add(newVersion);
            InfoVerList = CollectionViewSource.GetDefaultView(infoVerCollection);
            InfoVerList.CurrentChanged += InfoVerList_CurrentChanged;
        }

        public void SaveParam()
        {
            if (Confirm())
            {
                ResultValue result = new ResultValue();
                Para4006 param = new Para4006();
                Para4006Pk paramPk = new Para4006Pk();
                string timeValue = tmpByte;
                string xingqi = (this.XingQiCollection.CurrentItem as XingQi).Name;
                string xiaoshi = (this.XiaoShiCollection.CurrentItem as XiaoShi).Name;
                string min = (this.MinCollection.CurrentItem as Min).Name;
                int pos = this.ConvertDateToBinary(xingqi, xiaoshi, min);
                if (InfoVerList.CurrentItem == null)
                {
                    Microsoft.Windows.Controls.MessageBox.Show("请选择版本号!");
                    return;
                }
                paramPk.infoVer = (int)InfoVerList.CurrentItem;
                paramPk.recordId = this.RecordID;
                param.para4006Pk = paramPk;
                if (pos > 672)
                {
                    param.timeDef = tmpByte;
                    
                }
                else
                {
                    int tmpInfoVer = (int)InfoVerList.CurrentItem;
                    short infoVer = Int16.Parse(tmpInfoVer.ToString());
                    ObservableCollection<Para4006> para4006Collection = paramDao.GetObjectByInfoVer(infoVer);
                    if (para4006Collection.Count > 0)
                    {
                        Para4006 paramTmp = para4006Collection[0];
                        timeValue = paramTmp.timeDef;
                    }
                    StringBuilder sb = new StringBuilder(timeValue);
                    sb.Replace('1', '0', pos, 1);
                    param.timeDef = sb.ToString();
                    sb.Clear();
                }

                result = paramDao.CreateObject(param);

                if (result.Code == 0)
                {
                    Microsoft.Windows.Controls.MessageBox.Show("保存成功");
                    ReflashDataGrid();
                    CanclEditParam();
                }
                else
                {
                    Microsoft.Windows.Controls.MessageBox.Show("保存失败！发生错误:" + result.Msg);
                }
            }

        }

        private bool Confirm()
        {
            bool flag = true;
            /*
            if (this.LineID != null && !"".Equals(this.LineID) && this.LineNmCn != null && !"".Equals(this.LineNmCn) && !"".Equals(this.LineNmEn) && this.LineNmEn != null)
            {
                flag = true;
            }
            else
            {
                Microsoft.Windows.Controls.MessageBox.Show("所填信息不完整");
                flag = false;
            }
             */
            return flag;
        }

        private void CanclEditParam()
        {
            this.EditGroupBoxVisible = Visibility.Hidden;
            //将控件置为空
        }

        private void DelParam()
        {
            try
            {
                if (ParaCollectionDetail.CurrentItem != null)
                {
                    ParamDetail paramDetail = ParaCollectionDetail.CurrentItem as ParamDetail;
                    ObservableCollection<Para4006> para4006Collection = paramDao.GetObjectByInfoVer(paramDetail.InfoVer);
                    if (Microsoft.Windows.Controls.MessageBox.Show("确认删除所选择的参数！", "4006参数", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.OK)
                    {
                        if (para4006Collection.Count > 0)
                        {
                            Para4006 param = para4006Collection[0];
                            //删除
                            ResultValue result = paramDao.DeleteObject(param, param.para4006Pk.infoVer);
                            if (result.Code == 0)
                            {
                                Microsoft.Windows.Controls.MessageBox.Show("删除成功");
                                //刷新
                                InfoVerList = CollectionViewSource.GetDefaultView(paramDao.GetAllVersion());
                                InfoVerList.CurrentChanged += InfoVerList_CurrentChanged;

                                ReflashDataGrid();

                            }
                            else
                            {
                                Microsoft.Windows.Controls.MessageBox.Show("删除失败!发生错误：" + result.Msg);
                            }
                        }
                    }
                }
                else
                {
                    Microsoft.Windows.Controls.MessageBox.Show("未选择要删除的参数");
                }
            }
            catch (Exception e)
            {
            }
        }

        void InfoVerList_CurrentChanged(object sender, System.EventArgs ep)
        {
            if (InfoVerList.CurrentItem != null)
            {
                ReflashDataGrid();
            }
        }

        private void ReflashDataGrid()
        {
            int infoVer = (int)InfoVerList.CurrentItem;
            ObservableCollection<Para4006> paraCollection = paramDao.GetObjectByInfoVer(infoVer);

            if (paraCollection.Count > 0)
            {
                ParaCollectionDetail = CollectionViewSource.GetDefaultView(convert2ParamDetail(paraCollection));
            }
            else
            {
                ParaCollectionDetail = null;
            }
        }

        private int ConvertDateToBinary(string xingqi,string xiaoshi,string min)
        {
            int pos = 0;//周组位置
            int pos_xiaoshi = 0;
            int pos_min = 0;
            if (xingqi.Equals("星期天"))
            {
                pos = 96 * 0;
            }
            else if(xingqi.Equals("星期一"))
            {
                pos += 96 * 1;
            }
            else if (xingqi.Equals("星期二"))
            {
                pos += 96*2;
            }
            else if (xingqi.Equals("星期三"))
            {
                pos += 96*3;
            }
            else if (xingqi.Equals("星期四"))
            {
                pos += 96*4;
            }
            else if (xingqi.Equals("星期五"))
            {
                pos += 96*5;
            }
            else if (xingqi.Equals("星期六"))
            {
                pos += 96 * 6;
            }
            else if (xingqi.Equals("不设置高峰时段"))
            {
                pos += 999;
                return pos;
            }
            if (xiaoshi.Equals("00:00-01:00"))
            {
                pos_xiaoshi = pos + 1 * 4;
            }
            else if (xiaoshi.Equals("01:00-02:00"))
            {
                pos_xiaoshi = pos ;
            }
            else if (xiaoshi.Equals("02:00-03:00"))
            {
                pos_xiaoshi = pos + 3 * 4;
            }
            else if (xiaoshi.Equals("03:00-04:00"))
            {
                pos_xiaoshi = pos + 2 * 4;
            }
            else if (xiaoshi.Equals("04:00-05:00"))
            {
                pos_xiaoshi = pos + 5 * 4;
            }
            else if (xiaoshi.Equals("05:00-06:00"))
            {
                pos_xiaoshi = pos + 4 * 4;
            }
            else if (xiaoshi.Equals("06:00-07:00"))
            {
                pos_xiaoshi = pos + 7 * 4;
            }
            else if (xiaoshi.Equals("07:00-08:00"))
            {
                pos_xiaoshi = pos + 6 * 4;
            }
            else if (xiaoshi.Equals("08:00-09:00"))
            {
                pos_xiaoshi = pos + 9 * 4;
            }
            else if (xiaoshi.Equals("09:00-10:00"))
            {
                pos_xiaoshi = pos + 8 * 4;
            }
            else if (xiaoshi.Equals("10:00-11:00"))
            {
                pos_xiaoshi = pos + 11 * 4;
            }
            else if (xiaoshi.Equals("11:00-12:00"))
            {
                pos_xiaoshi = pos + 10 * 4;
            }
            else if (xiaoshi.Equals("12:00-13:00"))
            {
                pos_xiaoshi = pos + 13 * 4;
            }
            else if (xiaoshi.Equals("13:00-14:00"))
            {
                pos_xiaoshi = pos + 12 * 4;
            }
            else if (xiaoshi.Equals("14:00-15:00"))
            {
                pos_xiaoshi = pos + 15 * 4;
            }
            else if (xiaoshi.Equals("15:00-16:00"))
            {
                pos_xiaoshi = pos + 14 * 4;
            }
            else if (xiaoshi.Equals("16:00-17:00"))
            {
                pos_xiaoshi = pos + 17 * 4;
            }
            else if (xiaoshi.Equals("17:00-18:00"))
            {
                pos_xiaoshi = pos + 16 * 4;
            }
            else if (xiaoshi.Equals("18:00-19:00"))
            {
                pos_xiaoshi = pos + 19 * 4;
            }
            else if (xiaoshi.Equals("19:00-20:00"))
            {
                pos_xiaoshi = pos + 18 * 4;
            }
            else if (xiaoshi.Equals("20:00-21:00"))
            {
                pos_xiaoshi = pos + 21 * 4;
            }
            else if (xiaoshi.Equals("21:00-22:00"))
            {
                pos_xiaoshi = pos + 20 * 4;
            }
            else if (xiaoshi.Equals("22:00-23:00"))
            {
                pos_xiaoshi = pos + 23 * 4;
            }
            else if (xiaoshi.Equals("23:00-00:00"))
            {
                pos_xiaoshi = pos + 22 * 4;
            }
            //分钟
            if (min.Equals("0到15分钟"))
            {
                pos_min = pos_xiaoshi + 3;
            }
            else if (min.Equals("15到30分钟"))
            {
                pos_min = pos_xiaoshi + 2;
            }
            else if (min.Equals("30到45分钟"))
            {
                pos_min = pos_xiaoshi + 1;
            }
            else if (min.Equals("45到60分钟"))
            {
                pos_min = pos_xiaoshi + 0;
            }
            return pos_min;
        }

        private ObservableCollection<ParamDetail> convert2ParamDetail(string timeDef)
        {
            int infoVer = (int)InfoVerList.CurrentItem;
            ObservableCollection<ParamDetail> paramDetailCollection = new ObservableCollection<ParamDetail>();
            ParamDetail detail = null;
            for (int i = 0;i < 672 ;i++ )
            {
                
                string tmpValue = timeDef.Substring(i, 1);
                if (tmpValue.Equals("0"))
                {
                    detail = new ParamDetail();
                    detail.InfoVer = Int16.Parse(infoVer.ToString());
                    detail.GaoFeng = ConvertTimeDef2TimeDefine(i);
                    paramDetailCollection.Add(detail);
                }
            }
            return paramDetailCollection;
        }

        private ObservableCollection<ParamDetail> convert2ParamDetail(ObservableCollection<Para4006> paraCollection)
        {
            int infoVer = (int)InfoVerList.CurrentItem;
            ObservableCollection<ParamDetail> paramDetailCollection = new ObservableCollection<ParamDetail>();
            ParamDetail detail = null;
            foreach (Para4006 itme in paraCollection)
            {
                for (int i = 0; i < 672; i++)
                {

                    string tmpValue = itme.timeDef.Substring(i, 1);
                    if (tmpValue.Equals("0"))
                    {
                        detail = new ParamDetail();
                        detail.InfoVer = Int16.Parse(infoVer.ToString());
                        detail.GaoFeng = ConvertTimeDef2TimeDefine(i);
                        detail.RecordID = itme.para4006Pk.recordId;
                        paramDetailCollection.Add(detail);
                    }
                }
            }
            return paramDetailCollection;
        }

        private string ConvertTimeDef2TimeDefine(int pos)
        { 
            StringBuilder sb = new StringBuilder();
            //计算星期
            int xq = pos / 96;
            int xiaoshi = (pos - (xq * 96)) / 4;
            int fenzhong = pos - (xq * 96)  - (xiaoshi*4);
            if (xq == 0)
            {
                sb.Append("星期天");
            }
            else if (xq == 1)
            {
                sb.Append("星期一");
            }
            else if (xq == 2)
            {
                sb.Append("星期二");
            }
            else if (xq == 3)
            {
                sb.Append("星期三");
            }
            else if (xq == 4)
            {
                sb.Append("星期四");
            }
            else if (xq == 5)
            {
                sb.Append("星期五");
            }
            else if (xq == 6)
            {
                sb.Append("星期六");
            }
            sb.Append(" ");
            //解析小时
            if (xiaoshi == 1)
            {
                sb.Append("00:");
            }
            else if (xiaoshi == 0)
            {
                sb.Append("01:");
            }
            else if (xiaoshi == 3)
            {
                sb.Append("02:");
            }
            else if (xiaoshi == 2)
            {
                sb.Append("03:");
            }
            else if (xiaoshi == 5)
            {
                sb.Append("04:");
            }
            else if (xiaoshi == 4)
            {
                sb.Append("05:");
            }
            else if (xiaoshi == 7)
            {
                sb.Append("06:");
            }
            else if (xiaoshi == 6)
            {
                sb.Append("07:");
            }
            else if (xiaoshi == 9)
            {
                sb.Append("08:");
            }
            else if (xiaoshi == 8)
            {
                sb.Append("09:");
            }
            else if (xiaoshi == 11)
            {
                sb.Append("10:");
            }
            else if (xiaoshi == 10)
            {
                sb.Append("11:");
            }
            else if (xiaoshi == 13)
            {
                sb.Append("12:");
            }
            else if (xiaoshi == 12)
            {
                sb.Append("13:");
            }
            else if (xiaoshi == 15)
            {
                sb.Append("14:");
            }
            else if (xiaoshi == 14)
            {
                sb.Append("15:");
            }
            else if (xiaoshi == 17)
            {
                sb.Append("16:");
            }
            else if (xiaoshi == 16)
            {
                sb.Append("17:");
            }
            else if (xiaoshi == 19)
            {
                sb.Append("18:");
            }
            else if (xiaoshi == 18)
            {
                sb.Append("19:");
            }
            else if (xiaoshi == 21)
            {
                sb.Append("20:");
            }
            else if (xiaoshi == 20)
            {
                sb.Append("21:");
            }
            else if (xiaoshi == 23)
            {
                sb.Append("22:");
            }
            else if (xiaoshi == 22)
            {
                sb.Append("23:");
            }
            //解析分钟
            if (fenzhong == 3)
            {
                sb.Append("00-");
            }
            else if (fenzhong == 2)
            {
                sb.Append("15-");
            }
            else if (fenzhong == 1)
            {
                sb.Append("30-");
            }
            else if (fenzhong == 0)
            {
                sb.Append("45-");
            }
            //
            if (xiaoshi == 1)
            {
                sb.Append("00:");
            }
            else if (xiaoshi == 0)
            {
                sb.Append("01:");
            }
            else if (xiaoshi == 3)
            {
                sb.Append("02:");
            }
            else if (xiaoshi == 2)
            {
                sb.Append("03:");
            }
            else if (xiaoshi == 5)
            {
                sb.Append("04:");
            }
            else if (xiaoshi == 4)
            {
                sb.Append("05:");
            }
            else if (xiaoshi == 7)
            {
                sb.Append("06:");
            }
            else if (xiaoshi == 6)
            {
                sb.Append("07:");
            }
            else if (xiaoshi == 9)
            {
                sb.Append("08:");
            }
            else if (xiaoshi == 8)
            {
                sb.Append("09:");
            }
            else if (xiaoshi == 11)
            {
                sb.Append("10:");
            }
            else if (xiaoshi == 10)
            {
                sb.Append("11:");
            }
            else if (xiaoshi == 13)
            {
                sb.Append("12:");
            }
            else if (xiaoshi == 12)
            {
                sb.Append("13:");
            }
            else if (xiaoshi == 15)
            {
                sb.Append("14:");
            }
            else if (xiaoshi == 14)
            {
                sb.Append("15:");
            }
            else if (xiaoshi == 17)
            {
                sb.Append("16:");
            }
            else if (xiaoshi == 16)
            {
                sb.Append("17:");
            }
            else if (xiaoshi == 19)
            {
                sb.Append("18:");
            }
            else if (xiaoshi == 18)
            {
                sb.Append("19:");
            }
            else if (xiaoshi == 21)
            {
                sb.Append("20:");
            }
            else if (xiaoshi == 20)
            {
                sb.Append("21:");
            }
            else if (xiaoshi == 23)
            {
                sb.Append("22:");
            }
            else if (xiaoshi == 22)
            {
                sb.Append("23:");
            }
            //
            if (fenzhong == 3)
            {
                sb.Append("15");
            }
            else if (fenzhong == 2)
            {
                sb.Append("30");
            }
            else if (fenzhong == 1)
            {
                sb.Append("45");
            }
            else if (fenzhong == 0)
            {
                sb.Append("59");
            }
            string result = sb.ToString();
            sb.Clear();
            return result;
        }

        class XingQi
        {
            public XingQi(string name)
            {
                Name = name;
            }
            public string Name { get; set; }
        }

        class XiaoShi
        {
            public XiaoShi(string name)
            {
                Name = name;
            }
            public string Name { get; set; }
        }

        class Min
        {
            public Min(string name)
            {
                Name = name;
            }
            public string Name { get; set; }
        }

        class ParamDetail
        {
            public short InfoVer { get; set; }
            public string GaoFeng { get; set; }
            public int RecordID { get; set; }
        }
    }
}
